草庐IT

Beautiful Soup

全部标签

python - 使用 pip 安装 Beautiful Soup

这个问题在这里已经有了答案:python3--versionshows"NameError:name'python3'isnotdefined"(2个回答)关闭4年前。我正在尝试安装BeautifulSoup在Python2.7中使用pip。我不断收到错误消息,不明白为什么。我按照说明安装了pip,它安装到了以下目录:c:\Python27\Scripts\pip.exe。然后我尝试将它添加到路径中,并运行pipinstallpackage命令。我尝试了两种不同的方法:importsyssys.path.append('C:\\Python27\\Scripts\\pip.exe')p

python - 使用 pip 安装 Beautiful Soup

这个问题在这里已经有了答案:python3--versionshows"NameError:name'python3'isnotdefined"(2个回答)关闭4年前。我正在尝试安装BeautifulSoup在Python2.7中使用pip。我不断收到错误消息,不明白为什么。我按照说明安装了pip,它安装到了以下目录:c:\Python27\Scripts\pip.exe。然后我尝试将它添加到路径中,并运行pipinstallpackage命令。我尝试了两种不同的方法:importsyssys.path.append('C:\\Python27\\Scripts\\pip.exe')p

python - 如何使用 Python 检索网页的页面标题?

如何使用Python检索网页的页面标题(titlehtml标签)? 最佳答案 这里是@VinkoVrsalovic'sanswer的简化版本:importurllib2fromBeautifulSoupimportBeautifulSoupsoup=BeautifulSoup(urllib2.urlopen("https://www.google.com"))printsoup.title.string注意:soup.title在html文档中找到第一个title元素anywheretitle.string假设它只有一个子节点,并且

python - 如何使用 Python 检索网页的页面标题?

如何使用Python检索网页的页面标题(titlehtml标签)? 最佳答案 这里是@VinkoVrsalovic'sanswer的简化版本:importurllib2fromBeautifulSoupimportBeautifulSoupsoup=BeautifulSoup(urllib2.urlopen("https://www.google.com"))printsoup.title.string注意:soup.title在html文档中找到第一个title元素anywheretitle.string假设它只有一个子节点,并且

python - UnicodeEncodeError : 'ascii' codec can't encode character at special name

这个问题在这里已经有了答案:UnicodeEncodeError:'ascii'codeccan'tencodecharacteru'\xa0'inposition20:ordinalnotinrange(128)(34个回答)关闭6年前。我的python(ver2.7)脚本运行良好,可以从本地html文件中获取一些公司名称,但是当涉及到一些特定的国家名称时,它会给出这个错误“UnicodeEncodeError:'ascii'codeccan'tencodecharacter”当这个公司名称出现时特别出错公司名称:KühlfixKälteanlagenIng.GerhardDocze

python - UnicodeEncodeError : 'ascii' codec can't encode character at special name

这个问题在这里已经有了答案:UnicodeEncodeError:'ascii'codeccan'tencodecharacteru'\xa0'inposition20:ordinalnotinrange(128)(34个回答)关闭6年前。我的python(ver2.7)脚本运行良好,可以从本地html文件中获取一些公司名称,但是当涉及到一些特定的国家名称时,它会给出这个错误“UnicodeEncodeError:'ascii'codeccan'tencodecharacter”当这个公司名称出现时特别出错公司名称:KühlfixKälteanlagenIng.GerhardDocze

python - 使用 BeautifulSoup 根据 name 属性获取属性值

我想根据名字打印一个属性值,举个例子我想做这样的事情soup=BeautifulSoup(f)#fissomeHTMLcontainingtheabovemetatagformeta_taginsoup("meta"):ifmeta_tag["name"]=="City":print(meta_tag["content"])上面的代码给出了一个KeyError:'name',我相信这是因为name被BeatifulSoup使用了,所以它不能作为关键字参数。 最佳答案 很简单,使用如下:>>>frombs4importBeautifu

python - 使用 BeautifulSoup 根据 name 属性获取属性值

我想根据名字打印一个属性值,举个例子我想做这样的事情soup=BeautifulSoup(f)#fissomeHTMLcontainingtheabovemetatagformeta_taginsoup("meta"):ifmeta_tag["name"]=="City":print(meta_tag["content"])上面的代码给出了一个KeyError:'name',我相信这是因为name被BeatifulSoup使用了,所以它不能作为关键字参数。 最佳答案 很简单,使用如下:>>>frombs4importBeautifu

python - 我们可以将 XPath 与 BeautifulSoup 一起使用吗?

我正在使用BeautifulSoup抓取一个URL,并且我有以下代码,以查找其类为'empformbody'的td标记:importurllibimporturllib2fromBeautifulSoupimportBeautifulSoupurl="http://www.example.com/servlet/av/ResultTemplate=AVResult.html"req=urllib2.Request(url)response=urllib2.urlopen(req)the_page=response.read()soup=BeautifulSoup(the_page)so

python - 我们可以将 XPath 与 BeautifulSoup 一起使用吗?

我正在使用BeautifulSoup抓取一个URL,并且我有以下代码,以查找其类为'empformbody'的td标记:importurllibimporturllib2fromBeautifulSoupimportBeautifulSoupurl="http://www.example.com/servlet/av/ResultTemplate=AVResult.html"req=urllib2.Request(url)response=urllib2.urlopen(req)the_page=response.read()soup=BeautifulSoup(the_page)so